* Subject; Data process for poverty implications
* Date; 2020/01/29
* Name;  Shinichiro Fujimori

SET
  SCENARIOCGE                                 CGE scenario set
  REMF
;
$gdxin '../data/global_17_iamc.gdx'
$load SCENARIOCGE=SCENARIO REMF

SET
  Y/2000*2100/
  SCENARIO/SSP1,SSP2,SSP3,SSP4,SSP5
  SSP2_2deg,SSP2_1p5deg,SSP2_NDC
  SSP1_2deg,SSP1_1p5deg,SSP1_NDC
  SSP3_2deg,SSP3_1p5deg,SSP3_NDC
  SSP2_2deg_exempt,SSP2_1p5deg_exempt,SSP2_NDC_exempt
/
  MAPSCENARIOCGE(SCENARIO,SCENARIOCGE)                          CGE scenario set/
$  include ../define/ScenarioMapPov_gams.map
  /
  R                                                             Region/
$  include ../define/WDIcountry.set
  TWN
  AFR, ASP, CIS, EG2, EG1, OEE, RU2, RU1, SAM, WAS
  /

  VEMF                                      IAMC indicators/
    Rev_gov_Tax_Car_Tax_per_GDP
    Emi_CO2
    Prc_Car
    GDP_MER
    Emi_Kyo_Gas
    Emi_CO2_Ene_and_Ind_Pro
  /
  RMap(R,REMF)/
$include ../define/RegionmapAIMCGE.map
  /
  Ragg(R)/
    "R5OECD90+EU"
    R5ASIA
    R5LAM
    R5MAF
    R5REF
    WLD
  /
  Raggmap(R,Ragg)/
$include ../define/RegionmapR5.map
  /
  U/Gg,GgCO2eq/
  G/CH4
CO2
FGASESAR4
FGASES
HFCSAR4
HFCS
KYOTOGHGAR4
KYOTOGHG
N2O
PFCSAR4
PFCS
SF6
CO2ENE
/
 Cat/
CAT0
CAT1
CAT1A
CAT1B1
CAT1B2
CAT2
CAT2A
CAT2B
CAT2C
CAT2D
CAT2G
CAT3
CAT4
CAT5
CAT6
CAT7
CATM0EL
/
  TH Poverty threshold
  Gtax(G)/CO2,KYOTOGHG,CO2ENE/

;
*-----Load Data import from IAM results -----*


PARAMETER
  CGEload(SCENARIOCGE,REMF,VEMF,Y)                         CGE outputs
  CarbTaxRate(SCENARIOCGE,R,Y)                             Carbon tax rate from CGE outputs
  EMI_HIST(R,CAT,G,U,Y)                                    Historical CO2 & GHG emissions
  EMIScenario(SCENARIOCGE,R,Y,G)                           CO2 emissions scenarios rebased from Historical emissions | 1000tCO2
  CTAXScenario(SCENARIOCGE,R,Y,G)                          Carbn tax scenarios rebased from Historical emissions | billion$
  CTAXGDPRateScenario(SCENARIOCGE,R,Y,G)                   Carbn tax per GDP ratio scenarios rebased from Historical emissions | -
  GDPCap(SCENARIO,R,Y)                                     GDP per capita |PPP
  Population(SCENARIO,R,Y)                                 Population |
  PovGap_abs(SCENARIO,R,TH,Y)                              Poverty gap from income model | $
  PovGap_CtaxRev_Dif(SCENARIOCGE,R,TH,Y,G,*)               Poverty gap and carbon tax revenue differences | bil$ and per GDP
;

$gdxin '../data/global_17_iamc.gdx'
$load CGEload=IAMC_template

$gdxin '../data/HEM_RCI.gdx'
$load EMI_HIST

$gdxin '../data/Inputdata.gdx'
$load GDPCap Population TH

$gdxin '../data/AnalysisIncome.gdx'
$load PovGap_abs

CarbTaxRate(SCENARIOCGE,R,Y)=SUM(RMap(R,REMF),CGEload(SCENARIOCGE,REMF,"Rev_gov_Tax_Car_Tax_per_GDP",Y));
GDPCap(SCENARIO,Ragg,Y)$(SUM(Raggmap(R,Ragg),Population(SCENARIO,R,Y)))=SUM(Raggmap(R,Ragg),GDPCap(SCENARIO,R,Y)*Population(SCENARIO,R,Y))/SUM(Raggmap(R,Ragg),Population(SCENARIO,R,Y));
Population(SCENARIO,Ragg,Y)=SUM(Raggmap(R,Ragg),Population(SCENARIO,R,Y));
PovGap_abs(SCENARIO,R,TH,Y)=PovGap_abs(SCENARIO,R,TH,Y)/1000000000;

EMIScenario(SCENARIOCGE,R,Y,"CO2")=EMI_HIST(R,"CAT0","CO2","Gg","2010")*SUM(RMap(R,REMF)$(CGEload(SCENARIOCGE,REMF,"Emi_CO2","2010")),CGEload(SCENARIOCGE,REMF,"Emi_CO2",Y)/CGEload(SCENARIOCGE,REMF,"Emi_CO2","2010")) ;
EMIScenario(SCENARIOCGE,R,Y,"KYOTOGHG")=EMI_HIST(R,"CAT0","KYOTOGHG","GgCO2eq","2010")*SUM(RMap(R,REMF)$(CGEload(SCENARIOCGE,REMF,"Emi_Kyo_Gas","2010")),CGEload(SCENARIOCGE,REMF,"Emi_Kyo_Gas",Y)/CGEload(SCENARIOCGE,REMF,"Emi_Kyo_Gas","2010")) ;
EMIScenario(SCENARIOCGE,R,Y,"CO2ENE")=EMI_HIST(R,"CATM0EL","CO2","Gg","2010")*SUM(RMap(R,REMF)$(CGEload(SCENARIOCGE,REMF,"Emi_CO2","2010")),CGEload(SCENARIOCGE,REMF,"Emi_CO2_Ene_and_Ind_Pro",Y)/CGEload(SCENARIOCGE,REMF,"Emi_CO2_Ene_and_Ind_Pro","2010")) ;
CTAXScenario(SCENARIOCGE,R,Y,G)$(Gtax(G))=EMIScenario(SCENARIOCGE,R,Y,G)*1000*SUM(RMap(R,REMF),CGEload(SCENARIOCGE,REMF,"Prc_Car",Y))/1000000000;

EMIScenario(SCENARIOCGE,Ragg,Y,G)=SUM(Raggmap(R,Ragg),EMIScenario(SCENARIOCGE,R,Y,G));
CTAXScenario(SCENARIOCGE,Ragg,Y,G)=SUM(Raggmap(R,Ragg),CTAXScenario(SCENARIOCGE,R,Y,G));

CTAXGDPRateScenario(SCENARIOCGE,R,Y,G)$(SUM(SCENARIO$(MAPSCENARIOCGE(SCENARIO,SCENARIOCGE)),GDPCap(SCENARIO,R,Y)*Population(SCENARIO,R,Y)))
  =CTAXScenario(SCENARIOCGE,R,Y,G)/SUM(SCENARIO$(MAPSCENARIOCGE(SCENARIO,SCENARIOCGE)),GDPCap(SCENARIO,R,Y)*Population(SCENARIO,R,Y)/1000000000);


PovGap_CtaxRev_Dif(SCENARIOCGE,R,TH,Y,G,"abs")$(CTAXScenario(SCENARIOCGE,R,Y,G) AND SUM(SCENARIO$(MAPSCENARIOCGE(SCENARIO,SCENARIOCGE)),PovGap_abs(SCENARIO,R,TH,Y)))=CTAXScenario(SCENARIOCGE,R,Y,G)-SUM(SCENARIO$(MAPSCENARIOCGE(SCENARIO,SCENARIOCGE)),PovGap_abs(SCENARIO,R,TH,Y));
PovGap_CtaxRev_Dif(SCENARIOCGE,Ragg,TH,Y,G,"abs")=SUM(Raggmap(R,Ragg),PovGap_CtaxRev_Dif(SCENARIOCGE,R,TH,Y,G,"abs"));
PovGap_CtaxRev_Dif(SCENARIOCGE,R,TH,Y,G,"pGDP")$(SUM(SCENARIO$(MAPSCENARIOCGE(SCENARIO,SCENARIOCGE)),GDPCap(SCENARIO,R,Y)*Population(SCENARIO,R,Y)/1000000000))
  =PovGap_CtaxRev_Dif(SCENARIOCGE,R,TH,Y,G,"abs")/SUM(SCENARIO$(MAPSCENARIOCGE(SCENARIO,SCENARIOCGE)),GDPCap(SCENARIO,R,Y)*Population(SCENARIO,R,Y)/1000000000);
execute_unload '../output/gdx/CGEDataprocess.gdx'
CarbTaxRate
CTAXGDPRateScenario
CTAXScenario
EMIScenario
PovGap_CtaxRev_Dif
;

